package zky410;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class test {
    public static void main(String[] args) throws IOException {
        BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
        String[] s = sc.readLine().split(" ");
        int[] bills = new int[s.length];
        for(int i = 0 ;i<s.length;i++){
            bills[i] = Integer.parseInt(s[i]);
        }
        int res = billsChange(bills);
        System.out.println(res);
    }
    public static int billsChange (int[] bills) {
        // write code here
        ArrayList<Integer> list = new ArrayList<>();
        list.add(5);
        list.add(5);
        int num = 0;
        for(int i =0;i<bills.length;i++){
            int res = 0;
            res = bills[i] - 5;
            if(res == 0 ){
                num ++;
                list.add(5);
                continue;
            }
            if(res == 5){
                if(list.contains(5)){
                    list.add(10);
                    list.remove((Integer) 5);
                    num++;
                }else{
                    break;
                }
            }
            if(res == 15){
                if(list.contains(5)&&list.contains(10)){
                    list.add(20);
                    list.remove((Integer) 5);
                    list.remove((Integer) 10);
                    num++;
                }else{
                    break;
                }
            }
        }
        return num;
    }
}
